package com.share.user.api.factory;

import com.share.common.core.domain.R;
import com.share.user.api.RemoteUserInfoService;
import com.share.user.api.domain.UpdateUserLogin;
import com.share.user.api.domain.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/10/18 上午10:19
 */
@Component
@Slf4j
public class RemoteUserInfoFallbackFactory implements FallbackFactory<RemoteUserInfoService> {
    @Override
    public RemoteUserInfoService create(Throwable cause) {
        log.error("用户服务调用失败:{}", cause.getMessage());
        return new RemoteUserInfoService() {
            @Override
            public R<UserInfo> wxLogin(String code) {
                return R.fail("微信登录失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> updateUserLogin(UpdateUserLogin updateUserLogin) {
                return R.fail("更新用户登录失败：" + cause.getMessage());
            }

            @Override
            public R<UserInfo> getUserInfo(Long userId) {
                return R.fail("获取用户信息失败：" + cause.getMessage());
            }

            @Override
            public R<Map<String, Object>> getUserCount() {
                return R.fail("统计用户注册信息失败：" + cause.getMessage());
            }
        };
    }
}
